<template>
  <div>
    <el-card class="!border-none relative el-card-client" shadow="never">
      <template #header>
        <el-row :gutter="10">
          <el-col :span="5">
            <el-input
              class="mr_10 input_style"
              v-model="queryParams.title"
              clearable
              placeholder="请输入活动名称"
            />
          </el-col>
          <!-- <el-col :span="5">
            <el-select
              class="input_style mr_10"
              v-model="queryParams.status"
              clearable
              placeholder="请选择状态"
              @change="getStatus"
            >
              <el-option
                v-for="(item, index) in dictData.sh_status"
                :key="index"
                :label="item.name"
                :value="item.value"
              />
            </el-select>
          </el-col>-->
          <!-- <el-col :span="5">
            <el-select
              class="input_style mr_10"
              v-model="queryParams.type"
              clearable
              placeholder="请选择类型"
            >
              <el-option
                v-for="(item, index) in dictData.sh_type"
                :key="index"
                :label="item.name"
                :value="item.value"
              />
            </el-select>
          </el-col>-->
          <el-col :span="17">
            <el-button
              @click="getLists"
              color="#63ccba"
              type="primary"
              class="btn_style mr_10"
            >
              <template #icon>
                <el-icon color="#fff">
                  <Search />
                </el-icon>
              </template>
              搜索
            </el-button>
            <el-button @click="resetParams" icon="Refresh" plain
              >重置</el-button
            >
          </el-col>
          <!-- <el-col :span="2" class="flex justify-end">
            <move-button></move-button>
          </el-col> -->
        </el-row>
      </template>
      <div>
        <el-table
          :data="pager.lists"
          border
          @selection-change="handleSelectionChange"
          v-loading="pager.loading"
          stripe
          max-height="calc(100vh - 16rem)"
        >
          <el-table-column
            label="活动名称"
            show-overflow-tooltip
            align="center"
            prop="title"
          >
            <!-- <template #default="{ row }">
              <div class="flex curser_p" @click="handleEdit(row)">
                <div class="image mr_10">
                  <el-avatar shape="square" :src="row.image" />
                </div>
                <div class="text_left">
                  <p>{{ row.mobile }}</p>
                  <p>添加时间：{{ row.create_time }}</p>
                </div>
              </div>
            </template> -->
          </el-table-column>
          <el-table-column
            label="公司名字"
            prop="gs_name"
            show-overflow-tooltip
            align="center"
          />
          <el-table-column
            label="公司简介"
            prop="info"
            show-overflow-tooltip
            align="center"
          />
          <!-- <el-table-column label="选手图片" prop="status" align="center">
            <template #default="{ row }">
              <el-tag v-if="row.status == '0'" class="ml-2" type="info">
                <dict-value :options="dictData.sh_status" :value="row.status" />
              </el-tag>
              <el-tag v-if="row.status == '1'" class="ml-2" type="success">
                <dict-value :options="dictData.sh_status" :value="row.status" />
              </el-tag>
              <el-tag v-if="row.status == '2'" class="ml-2" type="warning">
                <dict-value :options="dictData.sh_status" :value="row.status" />
              </el-tag>
              <el-tag v-if="row.status == '-1'" class="ml-2" type="danger">
                <dict-value :options="dictData.sh_status" :value="row.status" />
              </el-tag>
            </template>
          </el-table-column> -->
          <el-table-column label="联系人" prop="name" align="center" />
          <el-table-column label="联系电话" prop="mobile" align="center" />
          <el-table-column label="操作" align="center">
            <template #default="{ row }">
              <!-- <el-button
                v-perms="['activity.zg_apply/edit']"
                size="small"
                type="primary"
                @click="handleEdit(row)"
                >详情</el-button
              > -->
              <el-button
                v-perms="['activity.zg_apply/edit']"
                size="small"
                type="danger"
                style="margin-left: 5px"
                @click="handleDelete(row.id)"
                >删除</el-button
              >
            </template>
          </el-table-column>
        </el-table>
      </div>
      <div class="flex mt-4 position">
        <pagination v-model="pager" @change="getLists" />
      </div>
    </el-card>
    <edit-dialog
      ref="editRef"
      :demoDialogRef="demoDialogRef"
      @close="demoDialogRef = false"
    ></edit-dialog>
  </div>
</template>

<script lang="ts" setup name="zgApplyLists">
import { usePaging } from "@/hooks/usePaging";
import { useDictData } from "@/hooks/useDictOptions";
import {
  apiZgApplyLists,
  apiZgApplyDelete,
  apiZgApplyDetail,
} from "@/api/zg_apply";
import { timeFormat } from "@/utils/util";
import feedback from "@/utils/feedback";
import EditPopup from "./edit.vue";
import EditDialog from "./dialog.vue";
import moveButton from "@/components/moveButton/index.vue";
import { unreadNotice } from "@/api/zg_activity";
import useAppStore from "@/stores/modules/app";
const appStore = useAppStore();

const editRef = shallowRef<InstanceType<typeof EditPopup>>();

// 查询条件
const queryParams = reactive({
  title: "",
  type: "",
  status: "0",
});
const getStatus = (row) => {};
// 选中数据
const selectData = ref<any[]>([]);

// 表格选择后回调事件
const handleSelectionChange = (val: any[]) => {
  selectData.value = val.map(({ id }) => id);
};

// 获取字典数据
const { dictData } = useDictData("sh_status,sh_type");

// 分页相关
const { pager, getLists, resetParams, resetPage } = usePaging({
  fetchFun: apiZgApplyLists,
  params: queryParams,
});

// 编辑
// 是否显示编辑框
const demoDialogRef = ref(false);
const handleEdit = async (data: any) => {
  demoDialogRef.value = true;
  let res = await apiZgApplyDetail({ id: data.id });
  editRef.value?.setFormData(res);
};

// 删除
const handleDelete = async (id: number | any[]) => {
  await feedback.confirm("确定要删除？");
  await apiZgApplyDelete({ id });
  getLists();
  getValue();
};

const getValue = async () => {
  const res = await unreadNotice({});
  nextTick(() => {
    appStore.unReadValueSave(res.NotAuditPlNum);
    appStore.ununReadValueZhuLi(res.HourLogNum);
  });
};
getLists();
</script>
<style lang="scss" scoped>
.flex {
  display: flex !important;
}

.btn_style {
  color: #fff;
}
.text_left {
  text-align: left;
}
.curser_p {
  cursor: pointer;
}
</style>
